//
// Created by syshen on 2021/7/6.
//

#ifndef GENERAL_OCR_UTILS_H
#define GENERAL_OCR_UTILS_H

#define CHECK(exp) \
if (exp != cudaSuccess) { \
printf("[ERROR] [%s:%d] %d\n", __FILE__, __LINE__, cudaGetLastError()); \
exit(-1); \
}

class Logger : public nvinfer1::ILogger {
public:

    Logger() : Logger(Severity::kWARNING) {}

    Logger(Severity severity) : reportableSeverity(severity) {}

    void log(Severity severity, const char *msg) override {
        // suppress messages with severity enum value greater than the reportable
        if (severity > reportableSeverity) return;

        switch (severity) {
            case Severity::kINTERNAL_ERROR:
                std::cerr << "INTERNAL_ERROR: ";
                break;
            case Severity::kERROR:
                std::cerr << "ERROR: ";
                break;
            case Severity::kWARNING:
                std::cerr << "WARNING: ";
                break;
            case Severity::kINFO:
                std::cerr << "INFO: ";
                break;
            default:
                std::cerr << "UNKNOWN: ";
                break;
        }
        std::cerr << msg << std::endl;
    }

    Severity reportableSeverity{Severity::kWARNING};
};

#endif //GENERAL_OCR_UTILS_H
